package com.zhuzi.demojfoenix;

import com.jfoenix.controls.JFXDecorator;
import com.zhuzi.demojfoenix.ui.View2Controller;
import io.datafx.controller.flow.Flow;
import io.datafx.controller.flow.FlowHandler;
import io.datafx.controller.flow.container.DefaultFlowContainer;
import io.datafx.controller.flow.context.FXMLViewFlowContext;
import io.datafx.controller.flow.context.ViewFlowContext;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class HelloApplication extends Application {
    @FXMLViewFlowContext
    private ViewFlowContext flowContext;


    @Override
    public void start(Stage stage) throws Exception {
        // FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
        Flow flow = new Flow(HelloController.class);
        DefaultFlowContainer container = new DefaultFlowContainer();
        flowContext = new ViewFlowContext();
        flowContext.register("Stage", stage);
        flow.createHandler(flowContext).start(container);

        JFXDecorator decorator = new JFXDecorator(stage, container.getView());
        // decorator.setCustomMaximize(true);
        // decorator.setGraphic(new SVGGlyph(""));

        stage.setTitle("JFoenix Demo");

        double width = 800;
        double height = 600;
        Scene scene = new Scene(decorator, width, height);
        stage.setResizable(false);
        stage.setScene(scene);
        stage.show();
    }


    /**
     * The main entry point for all JavaFX applications.
     * The start method is called after the init method has returned,
     * and after the system is ready for the application to begin running.
     *
     * <p>
     * NOTE: This method is called on the JavaFX Application Thread.
     * </p>
     *
     * @param primaryStage the primary stage for this application, onto which
     *                     the application scene can be set.
     *                     Applications may create other stages, if needed, but they will not be
     *                     primary stages.
     * @throws Exception if something goes wrong
     */
    public void start2(Stage primaryStage) throws Exception {
        new Flow(View2Controller.class).startInStage(primaryStage);
        // new Flow(HelloController.class).startInStage(primaryStage);
    }

    public void start3(Stage primaryStage) throws Exception {
        Flow flow = new Flow(View2Controller.class);
        FlowHandler flowHandler = flow.createHandler();

        StackPane pane = flowHandler.start(new DefaultFlowContainer());
        primaryStage.setScene(new Scene(pane));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}
